package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.common.Result;
import com.example.entity.GreenHouse;
import com.example.entity.SensorData;
import com.example.mapper.GreenHouseMapper;
import com.example.mapper.SensorDataMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class SensorDataService {

    @Resource
    private SensorDataMapper sensorDataMapper;

    public Result addSensorData(SensorData sensorData) {
        if(sensorDataMapper.addSensorData(sensorData)){
            return Result.success("插入成功",null);
        }else {
            return Result.error("插入失败");
        }
    }

    public List<SensorData> getSensorDataByIdList(List<Integer> idList){
        List<SensorData> sensorDataList = new ArrayList<>();
        for(Integer id : idList){
            sensorDataList.addAll(sensorDataMapper.getById(id));
        }
        return sensorDataList;
    }

    public List<SensorData> getTodaySensorDataByIdList(List<Integer> idList) {
        List<SensorData> sensorDataList = new ArrayList<>();
        Date date = new Date();
        date = DateUtil.date();
        for(Integer id : idList){
            sensorDataList.addAll(sensorDataMapper.getToday(date));
        }
        return sensorDataList;
    }

    public void deleteByGreenHouseId(Integer id) {
        sensorDataMapper.deleteByGreenHouseId(id);
    }
}
